// Decompiled by DJ v3.9.9.91 Copyright 2005 Atanas Neshkov  Date: 4/12/2007 10:47:53
// Home Page : http://members.fortunecity.com/neshkov/dj.html  - Check often for new version!
// Decompiler options: packimports(3) 
// Source File Name:   Vector2D.java

package mathematics;


// Referenced classes of package de.escape.quincunx.trafo:
//            Point2D, Point3D, Vector3D

public final class Vector2D
{

    public Vector2D()
    {
    }

    public Vector2D(Vector2D v)
    {
        x = v.x;
        y = v.y;
    }

    public Vector2D(Point2D p)
    {
        x = p.x;
        y = p.y;
    }

    public Vector2D(Vector3D v)
    {
        x = v.x;
        y = v.y;
    }

    public Vector2D(Point3D p)
    {
        x = p.x;
        y = p.y;
    }

    public Vector2D(float xx, float yy)
    {
        x = xx;
        y = yy;
    }

    public float length()
    {
        return (float)Math.sqrt(x * x + y * y);
    }

    public void scale(float f)
    {
        if(f != 1.0F)
        {
            x *= f;
            y *= f;
        }
    }

    public void normalize()
    {
        scale(1.0F / length());
    }

    public void add(Vector2D v)
    {
        x += v.x;
        y += v.y;
    }

    public Vector2D plus(Vector2D v)
    {
        Vector2D ret = new Vector2D(this);
        ret.add(v);
        return ret;
    }

    public Point2D plus(Point2D p)
    {
        Point2D ret = new Point2D(p);
        ret.add(this);
        return ret;
    }

    public void sub(Vector2D v)
    {
        x -= v.x;
        y -= v.y;
    }

    public Point2D minus(Point2D p)
    {
        Point2D ret = new Point2D(p);
        ret.sub(this);
        ret.scale(-1F);
        return ret;
    }

    public Vector2D minus(Vector2D v)
    {
        Vector2D ret = new Vector2D(this);
        ret.sub(v);
        return ret;
    }

    public float mult(Vector2D v)
    {
        return x * v.x + y * v.y;
    }

    public boolean equals(Vector2D v)
    {
        return v.x == x && v.y == y;
    }

    public String toString()
    {
        return new String((new StringBuffer()).append("<").append(x).append(",").append(y).append(">"));
    }

    public float x;
    public float y;
}